Dynomotion

Group: DynoMotion Message: 8724 From: eric_kato_sanders Date: 11/25/2013
Subject: Option for clean shutdown when KMotionCNC quits
Hi Tom,
Thanks for the tip on using one of the axis outputs for the charge pump.  It's working well.
One thing I noticed is I can shut down KMotionCNC and the coolant will remain on as well as the spindle, etc..  Is there a mechanism available to perform a shutdown of all of the outputs? If not, how about including a Shutdown option, perhaps in the Tools/Setup file tab, that would be executed when the application shuts down.
Eric
Group: DynoMotion Message: 8726 From: Tom Kerekes Date: 11/25/2013
Subject: Re: Option for clean shutdown when KMotionCNC quits
Hi Eric,

There is a global variable in KFLOP that increments each time a Host Application requests status.  You could write a watchdog type of program in KFLOP such that if the variable doesn't change in several seconds to shut things off.

extern int StatusRequestCounter;  // increments each time host requests status

Regards
TK


Group: DynoMotion Message: 8727 From: eric_kato_sanders Date: 11/26/2013
Subject: Re: Option for clean shutdown when KMotionCNC quits
Thanks Tom,
That sounds like a good workable option.
Since I'm working on my own version of KMotionCNC I ended up calling a Shutdown.c file from the destructor of my CDialog class I inherited from CKMotionCNCDlg.cpp.  I like the way your option would be self contained with the KFlop board however. Would running this at the end of my initialization program as a  while loop do the trick, calling Delay_sec(1) to check for a change every second?  Is Delay_sec pretty bandwidth friendly?
Eric

 



---In DynoMotion@yahoogroups.com, <tk@...> wrote:

Hi Eric,

There is a global variable in KFLOP that increments each time a Host Application requests status.  You could write a watchdog type of program in KFLOP such that if the variable doesn't change in several seconds to shut things off.

extern int StatusRequestCounter;  // increments each time host requests status

Regards
TK


Group: DynoMotion Message: 8728 From: eric_kato_sanders Date: 11/26/2013
Subject: Re: Option for clean shutdown when KMotionCNC quits
Tom, would this work?  I'm mostly concerned that the delay will keep the KFlop from performing other actions for a full second.  Is it better to simply let the thread run full speed and keep track of how many times the StatusRequestCounter remains the same, performing the shutdown if it hits a certain count?
  
   int RequestCounter = StatusRequestCounter;
   while(1)
   {
      WaitNextTimeSlice();
      Delay_sec(1);
      if(StatusRequestCounter != RequestCounter)
      {
         RequestCounter = StatusRequestCounter;
      }
      else
      {
         ShutDownSpindle();
         ShutDownCoolant();
         DisableAxis(0);
         DisableAxis(1);
         DisableAxis(2);
         DisableAxis(3);
         break;
      }
   }

 



---In DynoMotion@yahoogroups.com, <tk@...> wrote:

Hi Eric,

There is a global variable in KFLOP that increments each time a Host Application requests status.  You could write a watchdog type of program in KFLOP such that if the variable doesn't change in several seconds to shut things off.

extern int StatusRequestCounter;  // increments each time host requests status

Regards
TK


Group: DynoMotion Message: 8730 From: Moray Cuthill Date: 11/26/2013
Subject: Re: Option for clean shutdown when KMotionCNC quits
Eric,
 
would it not be better to use some kind of non-blocking delay loop?
This is just thrown together without checking the exact function names-
 
double DelayT = 0;
int StatusRequest = StatusRequestCounter;
 
if(DelayT <= Time_Sec() ){ 
  if(StatusRequest = StatusRequestCounter){
    //shutdown stuff here
  }
  StatusRequest = StatusRequestCounter;
  DelayT = time_sec() + 1;  // add however many seconds you want to wait before rechecking an update has happened
}
 
Moray


On Tue, Nov 26, 2013 at 1:05 PM, <eric@...> wrote:
 

Tom, would this work?  I'm mostly concerned that the delay will keep the KFlop from performing other actions for a full second.  Is it better to simply let the thread run full speed and keep track of how many times the StatusRequestCounter remains the same, performing the shutdown if it hits a certain count?
  
   int RequestCounter = StatusRequestCounter;
   while(1)
   {
      WaitNextTimeSlice();
      Delay_sec(1);
      if(StatusRequestCounter != RequestCounter)
      {
         RequestCounter = StatusRequestCounter;
      }
      else
      {
         ShutDownSpindle();
         ShutDownCoolant();
         DisableAxis(0);
         DisableAxis(1);
         DisableAxis(2);
         DisableAxis(3);
         break;
      }
   }

 



---In DynoMotion@yahoogroups.com, <tk@...> wrote:

Hi Eric,

There is a global variable in KFLOP that increments each time a Host Application requests status.  You could write a watchdog type of program in KFLOP such that if the variable doesn't change in several seconds to shut things off.

extern int StatusRequestCounter;  // increments each time host requests status

Regards
TK


Group: DynoMotion Message: 8734 From: Tom Kerekes Date: 11/26/2013
Subject: Re: Option for clean shutdown when KMotionCNC quits
Hi Eric,

That would possibly work, but it would block this thread for an entire second at a time.  This wouldn't cause KFLOP from performing other actions like motions or communication.  However if your system needs to do other things continuously then it is better to make the process unblocking and state driven checking times instead of doing delays.  That way one thread and one loop can service this and other things at the same time.

Regards
TK


Group: DynoMotion Message: 8735 From: eric_kato_sanders Date: 11/26/2013
Subject: Re: Option for clean shutdown when KMotionCNC quits
Thanks Tom,
I wasn't sure how the Delay function was implemented, (blocking or non blocking). 
This is the code I implemented.
   
    int RequestCounter = StatusRequestCounter;
   double nowTime = Time_sec();
   while(1)
   {
      WaitNextTimeSlice();
      if(Time_sec() - nowTime) > WATCH_DOG_TIME
      {
         nowTime = Time_sec();
         if(StatusRequestCounter != RequestCounter)
         {
            RequestCounter = StatusRequestCounter;
         }
         else
         {
            DisableAxis(0);
            DisableAxis(1);
            DisableAxis(2);
            DisableAxis(3);
            ShutDownSpindle();
            ShutDownCoolant();
            break;
         }
      }

 



---In DynoMotion@yahoogroups.com, <tk@...> wrote:

Hi Eric,

That would possibly work, but it would block this thread for an entire second at a time.  This wouldn't cause KFLOP from performing other actions like motions or communication.  However if your system needs to do other things continuously then it is better to make the process unblocking and state driven checking times instead of doing delays.  That way one thread and one loop can service this and other things at the same time.

Regards
TK


Group: DynoMotion Message: 8740 From: Tom Kerekes Date: 11/27/2013
Subject: Re: Option for clean shutdown when KMotionCNC quits
Hi Eric,

That would work, but the method you used only checks the counter every WATCH_DOG_TIME.  Depending on when the status stops it could be from one to two WATCH_DOG_TIMES before things are disabled.  Another method would be to check the counter continuously and then disable exactly one WATCH_DOG_TIME after the counter stops changing.  See below:

   int RequestCounter = StatusRequestCounter;
   double nowTime = Time_sec();
  
   while(1)
   {
      WaitNextTimeSlice();
     
      // Service disconnect/shutdown disables
      if(StatusRequestCounter != RequestCounter)
      {
         RequestCounter = StatusRequestCounter;
         nowTime = Time_sec();
      }
      else
      {
         if((Time_sec() - nowTime) > WATCH_DOG_TIME)
         {
            DisableAxis(0);
            DisableAxis(1);
            DisableAxis(2);
            DisableAxis(3);
            ShutDownSpindle();
            ShutDownCoolant();
            break;
         }
      }
   }

TK

Group: DynoMotion Message: 8746 From: eric_kato_sanders Date: 11/27/2013
Subject: Re: Option for clean shutdown when KMotionCNC quits

Tom,

What are the chances that the requeststatus counter might stay the same during normal operation for one loop?  I would hate for things to shut down during a run.  Would it be better to perhaps say if we get five non-changes in a row or something?

Eric




---In DynoMotion@yahoogroups.com, <tk@...> wrote:

Hi Eric,

That would work, but the method you used only checks the counter every WATCH_DOG_TIME.  Depending on when the status stops it could be from one to two WATCH_DOG_TIMES before things are disabled.  Another method would be to check the counter continuously and then disable exactly one WATCH_DOG_TIME after the counter stops changing.  See below:

   int RequestCounter = StatusRequestCounter;
   double nowTime = Time_sec();
  
   while(1)
   {
      WaitNextTimeSlice();
     
      // Service disconnect/shutdown disables
      if(StatusRequestCounter != RequestCounter)
      {
         RequestCounter = StatusRequestCounter;
         nowTime = Time_sec();
      }
      else
      {
         if((Time_sec() - nowTime) > WATCH_DOG_TIME)
         {
            DisableAxis(0);
            DisableAxis(1);
            DisableAxis(2);
            DisableAxis(3);
            ShutDownSpindle();
            ShutDownCoolant();
            break;
         }
      }
   }

TK

Group: DynoMotion Message: 8747 From: TK Date: 11/27/2013
Subject: Re: Option for clean shutdown when KMotionCNC quits
Hi Eric,

It would need to loop thousands of times with no status changes before disabling.  The time limit needs to be set for several seconds so that if Windows freezes for a while it won't trip. 

Regards
TK

On Nov 27, 2013, at 5:49 PM, <eric@...> wrote:

 

Tom,

What are the chances that the requeststatus counter might stay the same during normal operation for one loop?  I would hate for things to shut down during a run.  Would it be better to perhaps say if we get five non-changes in a row or something?

Eric




---In DynoMotion@yahoogroups.com, <tk@...> wrote:

Hi Eric,

That would work, but the method you used only checks the counter every WATCH_DOG_TIME.  Depending on when the status stops it could be from one to two WATCH_DOG_TIMES before things are disabled.  Another method would be to check the counter continuously and then disable exactly one WATCH_DOG_TIME after the counter stops changing.  See below:

   int RequestCounter = StatusRequestCounter;
   double nowTime = Time_sec();
  
   while(1)
   {
      WaitNextTimeSlice();
     
      // Service disconnect/shutdown disables
      if(StatusRequestCounter != RequestCounter)
      {
         RequestCounter = StatusRequestCounter;
         nowTime = Time_sec();
      }
      else
      {
         if((Time_sec() - nowTime) > WATCH_DOG_TIME)
         {
            DisableAxis(0);
            DisableAxis(1);
            DisableAxis(2);
            DisableAxis(3);
            ShutDownSpindle();
            ShutDownCoolant();
            break;
         }
      }
   }

TK

Group: DynoMotion Message: 8779 From: eric_kato_sanders Date: 12/4/2013
Subject: Re: Option for clean shutdown when KMotionCNC quits
Hi Tom,
Nuts, It looks like using the StatusRequestCounter won't work after all.  Opening a model dialog window in KMotionCNC stops the counter from updating.  I ended up running a shutdown.c file from the frame's destructor instead.

Eric

Group: DynoMotion Message: 8781 From: Tom Kerekes Date: 12/4/2013
Subject: Re: Option for clean shutdown when KMotionCNC quits
Hi Eric,

Hmmm...of course.

Regards
TK